//
// Created by Zsir on 2025/8/22.
//

#ifndef EPOLLPOLLER_H
#define EPOLLPOLLER_H

#include <vector>
#include <map>
#include <sys/epoll.h>

class Channel;
class EventLoop;

class EpollPoller {
public:
    using ChannelList = std::vector<Channel*>;

    EpollPoller(EventLoop* loop);
    ~EpollPoller();

    void poll(int timeoutMs, ChannelList* activeChannels);
    void updateChannel(Channel* channel);
    void removeChannel(Channel* channel);

private:
    void fillActiveChannels(int numEvents, ChannelList* activeChannels) const;
    void update(int operation, Channel* channel);

    static const int kInitEventListSize = 16;

    EventLoop* ownerLoop_;
    int epollfd_;
    std::vector<epoll_event> events_;
    std::map<int, Channel*> channels_;
};

#endif // EPOLLPOLLER_H
